/*
 * =====================================================================================
 *
 *       Filename:  getopt_long.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2013年01月10日 15时37分14秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>

int optindex;
int val;
struct option value[4]={
	{"sunjianxi",0,0,'s'},
	{"zhangxiaojuan",1,0,'z'},
	{"liuhuasong",2,0,'l'},
	{"yangxing",1,&val,'y'},
};

int main(int argc,char *argv[])
{
	int ret;
	while((ret=getopt_long(argc,argv,"sz:l::y:",value,&optindex))!= -1)
	{
		switch(ret)
		{
			case 's':
				printf("option is s ,optarg is %s \n",optarg);
				break;
			case 'z':
				printf("option is z ,optarg is %s \n",optarg);
				break;
			case 'l':
				printf("option is l,optarg is %s \n",optarg);
				break;
			case 'y':
				printf("option is y,optarg is %s \n",optarg);
				break;
			case 0:
				printf("ret is 0,option is %c,optarg is %s \n",val,optarg);
				break;
			case '?':
				printf("no option/dismiss \n");
				break;
		}
		printf("optindex is %d\n",optindex);
	}
}
